#!/bin/sh

download_thumbnails () {
	[ "$skip_thumb_download" -eq 1 ] && { print_info "Skipping thumbnail download\n"; return 0; }
	[ "$async_thumbnails" -eq 0 ] && print_info 'Fetching thumbnails...\n'
	curl_config_file="${session_temp_dir}/curl_config"
	[ -z "$*" ] && return 0
	: > "$curl_config_file"
	for line in "$@"; do
        _url="${line%%;*}" _id="${line##*;}"
        [ -f "${YTFZF_CUSTOM_THUMBNAILS_DIR}/${_id}.jpg" ] && continue
		printf "url=\"%s\"\noutput=\"$YTFZF_CUSTOM_THUMBNAILS_DIR/%s.jpg\"\n" "${_url}" "${_id}"
	done >> "$curl_config_file"
    ! [ -s "$curl_config_file" ] && return 0
	[ "$async_thumbnails" -eq 1 ] && use_silent="s"
	curl -${use_silent}fLZ -K "$curl_config_file"
	[ $? -eq 2 ] && curl -${use_silent}fL -K "$curl_config_file"
}
